<template>
    <uni-popup ref="popupForPrivacy" :safe-area="false">
        <div class="popupForPrivacy">
            <div class="title">
                {{ title }}
            </div>
            <view class="weui-half-screen-dialog__bd">
                <view class="weui-half-screen-dialog__tips">{{ desc1 }}</view>
                <view
                    class="weui-half-screen-dialog__tips"
                    style="color: blue"
                    @click="openPrivacyContract"
                    >{{ urlTitle }}</view
                >
                <view class="weui-half-screen-dialog__tips">{{ desc2 }}</view>
            </view>
            <div class="btns fx jcc">
                <button
                    open-type="agreePrivacyAuthorization"
                    class="agree fx jcc"
                    @agreeprivacyauthorization="onAgree"
                >
                    同意
                </button>
            </div>
        </div>
    </uni-popup>
</template>

<script>
import $ from "@/common";
export default {
    data() {
        return {
            title: "用户隐私保护提示",
            desc1: "感谢您使用本产品，您使用本产品前应当阅读并同意",
            urlTitle: "《用户隐私保护指引》",
            desc2: "当您点击同意并开始使用产品服务时，即表示您已理解并同意该条款内容，该条款将对您产生法律约束力。",
        };
    },
    methods: {
        openPrivacyContract() {
            wx.openPrivacyContract({
                success: (res) => {
                    console.log("openPrivacyContract success");
                },
                fail: (res) => {
                    console.error("openPrivacyContract fail", res);
                },
            });
        },
        onAgree() {
            $.log("agree");
            this.$refs.popupForPrivacy.close();
        },
    },
    mounted() {
        if (wx.getPrivacySetting) {
            wx.getPrivacySetting({
                success: (res) => {
                    this.urlTitle = res.privacyContractName;
                    console.log(res);
                    if (res.needAuthorization) {
                        this.$refs.popupForPrivacy.open("center");
                    }
                },
                fail: () => {},
                complete: () => {},
            });
        }
    },
};
</script>

<style lang="less" scoped>
.popupForPrivacy {
    background: #fff;
    width: 500rpx;
    padding: 30rpx;
    border-radius: 10rpx;
    line-height: 1.5;
    .title {
        font-size: 32rpx;
        font-weight: bold;
        text-align: center;
        padding-bottom: 30rpx;
    }

    .agree {
        margin-top: 30rpx;
        width: 100%;
        height: 80rpx;
        background: #07c160;
        color: #fff;
    }
}
</style>

